/*
 * CatCakePlatform.h
 *
 *  Created on: 2012/9/24
 *      Author: apple
 */

#ifndef CATCAKEPLATFORM_H_
#define CATCAKEPLATFORM_H_

#include <wild/PlatformMgr.h>
#include <wild/TraceLog.h>
#include <catcake.h>
//#include <task/ck_task_util.h>
//#include <task/ck_task.h>
#include <wild/GlobeTimer.h>

namespace wild
{
namespace android
{


template < typename PLATFORM >
class CkWorker : public ckTask
{
public:
	//CkWorker(wild::Platform* p);

	//virtual ~CkWorker();
	CkWorker()
	: ckTask(ORDER_ZERO)
	, m_ptr(0)
	{


		m_ptr = new PLATFORM();
		m_ptr->Initialize();
		m_ptr->Start();


	}

	~CkWorker()
	{
		if(m_ptr)
		{
			m_ptr->Stop();
			m_ptr->Finialize();
		}

		SAFE_DEL( m_ptr );


	}

	virtual void onUpdate()
	{
		if(m_ptr)
			m_ptr->UpdateFrame();
	}
private:

private:
	wild::Platform* m_ptr;
};






template < typename PLATFORM >
class CkStarter : public wild::Singleton< CkStarter<PLATFORM> >
{
	typedef CkWorker<PLATFORM> PLATFORM_TYPE;
public:



	void Start(Uint width, Uint height)
	{
		ckCreateCatcake("Wild Game", width, height, 60, ckSysMgr::FLAG_VARIABLE_SIZE);
		ckNewTask(PLATFORM_TYPE);
		ckStartCatcake();



	}

	void Stop()
	{
		//ckDeleteTask();

		ckEndCatcake();

		ckDestroyCatcake();
	}


private:

};

class CatCakePlatform : public wild::Platform
{
public:
	CatCakePlatform() : m_iScene(IWA_NULL) {}
protected:
	virtual bool OnConfigure(void);
	virtual void OnStart();
	virtual void OnStop();
	virtual void OnUpdate();


protected:
	wild::TraceLog m_oLogmgr;
	int m_iScene;
};



}
}


#endif /* CATCAKEPLATFORM_H_ */
